package com.t2t.top.gc;

/**
 * Created by Administrator on 2016/9/15.
 */
public class TestGC {
    private static final int _1MB = 1024 * 1024;

    public static void main(String[] args) {
        //testPretenureSizeThreshold();
        testTenuringThreshold();
    }

    /**
     * -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=1 -XX:+PrintTenuringDistribution
     */
    public static void testTenuringThreshold() {
        byte[] a, b, c;
        a = new byte[_1MB / 4];//256k
        //什么时候进入老年代取决于XX:MaxTenuringThreshold设置
        b = new byte[4 * _1MB];
        c = new byte[4 * _1MB];
        c = null;
        c = new byte[4 * _1MB];
    }

    /**
     * -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
     * 大对象直接进老年代
     */
    public static void testPretenureSizeThreshold() {
        byte[] a = new byte[8 * _1MB];
    }

    /**
     * -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
     * 新生代Minor GC
     */
    public static void testAllocation() {
        byte[] a, b, c, d;
        a = new byte[2 * _1MB];
        b = new byte[2 * _1MB];
        c = new byte[3 * _1MB];
        d = new byte[4 * _1MB];
    }


    @Override
    protected void finalize() throws Throwable {
        System.out.println("finalize ......");
    }
}
